<!--    客户管理-客户详情---添加 回访记录组件  by jh   -->
<template>
    <div>
        <el-form :model="form" label-width="80px" class="editRetVisit">
            <el-row>
                <el-col class="operateButton" :span="5">
                    <div class="ca-title"><h3 class="h3">编辑回访记录：</h3></div>
                </el-col>
                <el-col class="pull-right operateButton" :span="6">
                        <el-button size="medium" @click="deleteRecord">删除</el-button>
                        <el-button size="medium" type="primary" @click="onSubmit">保存</el-button>
                        <el-button size="medium" @click="editReturnVisitFun(itemData)">取消</el-button>
                </el-col>
            </el-row>
            <el-row :gutter="10">
                <el-col :span="12">
                    <el-form-item label="回访时间">
                        <el-date-picker
                            class="full-width"
                            v-model="form.listGuestVisit[0].visitTime"
                            type="date"
                            placeholder="选择日期">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="回访人">
                        <el-input v-model="form.listGuestVisit[0].visitUser" :maxlength="100"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col>
                    <el-form-item label="内容记录">
                        <el-input type="textarea" placeholder="1000字" v-model="form.listGuestVisit[0].content" :maxlength="1000"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col>
                    <el-form-item label="待办事项">
                        <el-input type="textarea" placeholder="1000字" v-model="form.listGuestVisit[0].remark" :maxlength="1000"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col>
                    <el-form-item label="文件上传">
                        <!--<csUploadButton-->
                            <!--:fileType="fileType"-->
                            <!--:businessId="guestId"-->
                            <!--&gt;-->
                        <!--</csUploadButton>-->
                    </el-form-item>
                    <csListEdit
                        :isEditSaveBtn="false"
                        :isEditCancelBtn="isEditCancelBtn"
                        :isShowFileChildType='isShowFileChildType'
                        :isShowSearch="isShowSearch"
                        :fileType="fileType"
                        :businessId="form.listGuestVisit[0].id"
                        :getFileUploadedReturnData="getFileUploadedReturnData"
                        :deleteFileId="deleteFileId"
                    ></csListEdit>
                </el-col>
            </el-row>
        </el-form>

    </div>
</template>

<script type="text/ecmascript-6">
    import {api} from '__views/client-management/api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    export default {
        props: {
            editReturnVisitFun: {  //编辑回访 ---回访详情  切换
                type: Function,
                required: true
            },
            itemData: {
                type: Object,
                required: true
            },
        },
        data() {
            return {
                isEditCancelBtn: false,
                isShowSearch: false,
                isShowFileChildType: false,
                fileType: '10062',//文件上传的参数
                guestId: this.$route.params.eClient_guestId,
                form: {
                    'fileListId': this.itemData.filesVoList,
                    'guestId': this.itemData.guestId,
                    'listGuestVisit': [
                        {
                            'content': this.itemData.content, //内容记录
                            'guestId': this.itemData.guestId,
                            'id': this.itemData.id,
                            'remark': this.itemData.remark,//待办事项
                            'visitTime': new Date(this.itemData.visitTime),//时间
                            'visitUser': this.itemData.visitUser //回访人
                        }
                    ],
                    'visitId': this.itemData.id
                }
            }
        },
        watch: {

        },
        created() {
        },
        mounted() {
            this.initView()
        },
        methods: {
            //获取删除文件的id
            deleteFileId(id) {
                this.form.fileListId.map((item,index) => {
                   if (item === id) {
                       this.form.fileListId.splice(index,1)
                   }
                })
            },
            //文件上传成功之后返回的数组
            getFileUploadedReturnData(arr) {
                arr.map((item)=> {
                    this.form.fileListId.push(item.id)
                })
            },
            initView() {//页面赋值
                //文件id 赋值
                let arr = []
                this.itemData.filesVoList.map((item)=>{
                    arr.push(item.id)
                })
                this.form.fileListId = arr
            },
            //编辑回访记录--提交
            onSubmit() {
                let that = this
                let params = Object.assign({},this.form)
                //格式化时间
                params.listGuestVisit[0].visitTime = params.listGuestVisit[0].visitTime.getTime()
                apiHttp(api.ADD_RETURN_RECORD,params).then(ret=> {
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.$message({
                            message: '修改成功',
                            type: 'success',
                            center: true
                        });
                        that.$emit('getReturnRecordList')
                        that.editReturnVisitFun(this.itemData) //关闭编辑
                    }
                })
            },
            //删除回访记录
            deleteRecord() {
                this.$confirm('是否删除此回访信息?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let that = this
                    let params = {
                        visitId: this.form.visitId
                    }
                    apiHttp(api.DELETE_RETURN_RECORD,params).then(ret=> {
                        if (ret.resCode === STATUS_HTTP_SUCCESS) {
                            this.$message({
                                type: 'success',
                                message: '删除成功!',
                                center: true
                            });
                            that.$emit('getReturnRecordList')
                            that.editReturnVisitFun(this.itemData)
                        }
                    })
                },() => {
//                    this.$message({
//                        type: 'info',
//                        message: '已取消删除',
//                        center: true
//                    });
                })
            }
        },
        components: {
            'csListEdit': require('__components/file-list/edit.vue'),//回访记录 列表与编辑
            //'csUploadButton': require('__components/upload-btn'),//上传按钮
          },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
    .operateButton{
      margin-bottom: 20px;
    }
    .editRetVisit{
        margin-bottom: 20px;
        padding: 30px 10px  30px 20px;
    }
    .full-width{
        width:100%;
    }
    //隐藏组件的多余功能
    /*.listEdit{*/
        /*.ca-file-main{*/
            /*.ca-title{*/
                /*.el-row>div{*/
                    /*&:nth-child(1),&:nth-child(2),&:nth-child(3){*/
                        /*display: none !important;*/
                    /*}*/
                    /*&:nth-child(4)>button{*/
                            /*display: none;*/
                        /*}*/
                    /*&:nth-child(4)>div{*/
                       /*float: right;*/
                    /*}*/
                /*}*/

            /*}*/
        /*}*/
        /*//隐藏组件的多余功能*/
        /*.el-dialog{*/
            /*.el-dialog__body{*/
                /*form>div:first-child{*/
                    /*display: none;*/
                /*}*/

            /*}*/
        /*}*/
    /*}*/

</style>
